/**
 * 
 */
package jvs.sh;

/**
 * @author qiangli
 *
 */
public class Man {
	// abort
	// shell/bye|exit|quit
	// help|man|info
	// pwd cd|chdir ls|dir|list|directory mkdir|md rmdir|rd rm|remove|del|delete mv|move cp|copy
	// view|cat|type file|attr|attrib|attribute
	// df du ln|link/unlink mount/unmount
	// javac dex java bsh ant 
	// at bg kill
	// jar/unjar zip/unzip md5 
	// put get
	//
	// PUT GET uri (http:// ftp:// ~email)
	// ENC DEC -url | -base64
	// GROUPADD GROUPMOD GROUPDEL
	// USERADD USERMOD USERDEL
	// CHMOD FIND FC
	// MAIL WEBGET FTP RSH RCP
	//
	
	public static final String[][] manual = new String[][] {
		{"abort",  "abort     Abort all current long running tasks in separate threads  (such as find, du, put, get)"},
		{"*ant",  "ant <file> [target]     Apache ANT  (TBD)"},
		{"*attr", "attr [file]      List file attribute"},
		{"*bsh",  "bsh <script>     Run Bean Shell (TBD)"},
		{"buzz",  "buzz     Ring the site owner (TBD)"},
		{"bye",  "bye      Disconnect from shell and release resources"},
		{"cat",  "cat <file>    Show content of text file"},
		{"cd",  "cd [file].    Change directory If arugment is missing, it defaults to /public for public user, /shared/~[buddy] for buddy, and v:/ for admin"},
		{"chksum",  "chksum <file>    Compute file checksum"},
		{"cp",  "cp <from-file> <to-file>    Copy file"},
		{"date",  "date [format]    Show date on the host device.  see http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html"},
		{"dec",  "dec <uri>     Decode"},
		{"*dex",  "dex <file>   [output-file]    convert Java class into DEX  format (TBD)"},
		{"*df",  "df    Display all mounted file systems"},
		{"dir",  "dir [file]    Simple directory listing"},
		{"du",  "du [file]    Disk space usage"},
		{"echo",  "echo [text]    Echo back text "},   
		{"edit",  "edit <file> [text]   Text editor"}, 
		{"enc",  "enc <uri>    Encode"}, 
		{"env",  "env    List environment variables"},
		{"find",  "find <start-file> <regex>  Find files with regular expression. see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html"},
		{"get",  "get <file>    Download file (not working in all cases)"},
		{"*grant",  "grant <user> <role>    Grant temporary  admin privilege to buddy (TBD)"},
		{"grep",  "grep <file> <regex>    Find text in file. see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html"},
		{"group",  "group [user]    List all groups in buddy list  or a specified user's  groups (admin)  or the current user's groups (buddy)"},
		{"*groupadd",  "groupadd <group>    Add group to buddy list"},
		{"*groupdel",  "groupdel <group>     Delete group from buddy list"},
		{"*groupmod",  "groupmod <old-group> <new-group>    Modify/rename group."},
		{"head",  "head <file>  [number]     Show first few lines/bytes of a file"},
		{"help",  "help   This help page"},
		{"info",  "info [file]     Show file attribute"},
		{"id",  "id    Show connected user id (JID)"},
		{"*java",  "java <file>    Run Java (TBD)"},
		{"*javac",  "javac <file> [out-file]    Compile Java source into java class file (TBD)"},
		{"*link",  "link <file> <URI>     Link current file to another URI"},
		{"list",  "list [file | file offset | file offset max]     Full directory listing"},
		{"listc",  "listc  [file | file index]    Full directory listing with pagination index info "},
		{"listp",  "listp [file | file regexp]   Full directory listing with regular expression filtering. see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html"},
		{"mkdir",  "mkdir <file>    Make new directory  or add group to buddy list"},
		{"motd",  "motd    Print message of the day from the site owner"},
		{"*mount",  "mount <path> <URI> [r | rw]    Map an URI to a virtual path with read or read-write access"},
		{"mv",  "mv <from-file> <to-file>    Move/rename file"},
		{"note",  "note [file]    Show all notes/comments attached to a file"},
		{"noteadd",  "noteadd [file]    Attach a note to file"},
		{"ping",  "ping <jid>     Ping remote buddy if he/she also runs command shell"},
		{"plan",  "plan      Show site owner's plan"},
		{"pull",  "pull <file> -- for application only as data stream is required"},
		{"push",  "push <file> -- for application only as data stream is required (TBD)"},
		{"put",  "put <file>    Upload file (not working in all cases)"},
		{"pwd",  "pwd    Print current working directory"},
		{"*revoke",  "revoke <role> <user>    Revoke temporary priviledged access granted to buddy (TBD)"},
		{"rm",  "rm <file>    Remove/delete file"},
		{"rmdir",  "rmdir <file>      Remove/delete empty folder"},
		{"set",  "set <name> = <value>    Set environment variable"},
		{"touch",  "touch <file>    Create new file or change file modified time.  or add buddy to group"},
		{"*unlink",  "unlink <file>    Remove the link to URI"},
		{"*unmount",  "unmount <path>    Dismount file system"},
		{"unset",  "unset <name>    Clear enviroment variable"},
		{"*unwatch",  "unwatch <file>    Remove file from watch list"},
		{"*user",  "user [group]    List all buddies in  buddy list or in a group"},
		{"*useradd",  "useradd <group> <jid> <name>    Add buddy to group"},
		{"*userdel",  "userdel <group> <jid>      Remove buddy from group"},
		{"*usermod",  "usermod <jid> <new-name>    Modify buddy name"},
		{"*watch",  "watch <file>    Put file into watch list"},
		{"who",  "who     List all users currently connected to the shell"},
		{"whoami",  "whoami    Show user id (JID)"},
		{"*write",  "write <jid>  <text>    Send a short message"}
	};

	/**
	 * 
	 */
	private Man() {
	}

	public static String help() {
		return help(null);
	}

	public static String help(String cmd) {
		StringBuffer sb = new StringBuffer();
		if (cmd == null) {
			for (String[] m: manual) {
				sb.append(m[0]);
				sb.append(" ");
			}
		} else {
			cmd = cmd.toLowerCase();
			String starcmd = "*"+cmd;
			for (String[] m: manual) {
				if (m[0].equals(cmd)  || m[0].equals(starcmd)) {
					sb.append(m[1]);
					break;
				}
			}
		}
		return sb.toString();
	}
}
